prices = [8,4,6,2,3]
[4,2,4,2,3]

var finalPrices = function(prices) {
    const n =prices.length
    let ans=[...prices]
    let stack =[]
    for(let i=0;i<n;i++){
        while(stack.length&&prices[i]<=prices[stack[stack.length-1]]){
            const idx =stack.pop()
            ans[idx] =prices[idx]-prices[i]
        }
        stack.push(i)
    }
    return ans
};